package com.ying.tests.AAAVIP;

import sun.misc.Launcher;

import java.net.URL;
import java.util.Arrays;

public class Test1JdkClassLoader {
    public static void main(String[] args) {

        // 引导类加载器，核心类库，jdk/jre/lib
        System.out.println(String.class.getClassLoader());
        // 扩展类加载器，扩展类库，jdk/jre/lib/ext
        System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader());
        // 应用类加载器
        System.out.println(Test1JdkClassLoader.class.getClassLoader());
        System.out.println("----------------------------------------------------------");

        ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
        ClassLoader extClassLoader = appClassLoader.getParent();
        ClassLoader bootstrapLoader = extClassLoader.getParent();
        System.out.println("the bootstrapLoader : " + appClassLoader);
        System.out.println("the appClassLoader : " + extClassLoader);
        System.out.println("the extClassLoader : " + bootstrapLoader);
        System.out.println("----------------------------------------------------------");

        System.out.println("bootstrapLoader加载以下文件：");
        URL[] urls = Launcher.getBootstrapClassPath().getURLs();
        Arrays.stream(urls).forEach(url -> System.out.println(url));

        System.out.println("extClassLoader加载以下文件：");
        System.out.println(System.getProperty("java.ext.dirs"));

        System.out.println("appClassLoader加载以下文件：");
        System.out.println(System.getProperty("java.class.path"));
        System.out.println("----------------------------------------------------------");


    }
}
